package net.blogways.ordermgr.util;

import java.util.Random;

/**
 * @author chenxin
 * created on  2017/10/21
 */
public class RandomToken {

  /**
   * 随机生成数字编码.
   *
   * @return
   */
  public static String randomNum(int length) {
    String str = "0123456789";
    StringBuilder token = new StringBuilder(length);
    for (int i = 0; i < length; i++) {
      char ch = str.charAt(new Random().nextInt(str.length()));
      token.append(ch);
    }
    return token.toString();
  }


  /**
   * 随机生成英文加数字编码.
   *
   * @param length
   * @return
   */
  public static String randomEnNum(int length) {
    String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    StringBuilder token = new StringBuilder(length);
    for (int i = 0; i < length; i++) {
      char ch = str.charAt(new Random().nextInt(str.length()));
      token.append(ch);
    }
    return token.toString();
  }

  /**
   * 随机生成英文大小写加数字编码.
   *
   * @param length
   * @return
   */
  public static String randomEnNumSec(int length) {
    String str = "abcdefghijklmnopqrstuvwxyz0123456789";
    StringBuilder token = new StringBuilder(length);
    for (int i = 0; i < length; i++) {
      char ch = str.charAt(new Random().nextInt(str.length()));
      token.append(ch);
    }
    return token.toString();
  }
}
